package cc.rengu.igas.share.facade.bean.cups;

import cc.rengu.oltp.service.common.enums.OltpRpcdEnum;
import cc.rengu.oltp.service.model.BizException;

import java.util.Arrays;

/**
 * F39 应答码
 *
 * @author fangminwei
 * @date 2021/4/17
 */
@SuppressWarnings("AlibabaEnumConstantsMustHaveComment")
public enum F39_RspCodeEnum implements CupsRspCodeEnum.Type {
    _00("00", "承兑或交易成功"),
    _01("01", "查发卡方"),
    _03("03", "无效商户"),
    _04("04", "没收卡"),
    _05("05", "身份认证失败"),
    _10("10", "部分金额批准"),
    _11("11", "重要人物批准（VIP）"),
    _12("12", "无效的关联交易"),
    _13("13", "无效金额"),
    _14("14", "无效卡（无此账号）"),
    _15("15", "无此发卡方"),
    _16("16", "批准更新第三磁道"),
    _20("20", "保留使用（境外二维码业务保留"),
    _21("21", "卡未初始化"),
    _22("22", "故障怀疑，关联交易错"),
    _25("25", "找不到原始交易"),
    _30("30", "报文格式错误"),
    _34("34", "有作弊嫌疑"),
    _38("38", "超过允许的PIN试输入"),
    _40("40", "请求的功能尚不支持"),
    _41("41", "挂失卡"),
    _43("43", "被窃卡"),
    _45("45", "不允许降级交易"),
    _51("51", "资金不足"),
    _54("54", "过期的卡"),
    _55("55", "不正确的PIN"),
    _57("57", "不允许持卡人进行的交易"),
    _58("58", "不允许终端进行的交易"),
    _59("59", "有作弊嫌疑"),
    _61("61", "超出金额限制"),
    _62("62", "受限制的卡"),
    _64("64", "原始金额错误"),
    _65("65", "超出取款/消费次数限制"),
    _68("68", "发卡行响应超时"),
    _75("75", "允许的输入PIN次数超限"),
    _90("90", "正在日终处理（）"),
    _91("91", "发卡方不能操作"),
    _92("92", "金融机构或中间网络设施找不到或无法达到"),
    _94("94", "重复交易"),
    _96("96", "银联处理中心系统异常、失效"),
    _97("97", "ATM/POS终端号找不到"),
    _98("98", "银联处理中心收不到发卡方应答"),
    _99("99", "PIN格式错"),
    _A0("A0", "MAC鉴别失败"),
    _A1("A1", "转账货币不一致"),
    _A2("A2", "有缺陷的成功"),
    _A3("A3", "资金到账行无此账户"),
    _A4("A4", "有缺陷的成功"),
    _A5("A5", "有缺陷的成功"),
    _A6("A6", "有缺陷的成功"),
    _A7("A7", "安全处理失败"),
    _A8("A8", "转入卡归属地信息缺失"),
    _A9("A9", "保留使用"),
    _B1("B1", "无欠费（收据未打）"),
    _C1("C1", "受理方状态非法"),
    _D1("D1", "机构代码错误"),
    _D2("D2", "日期错误"),
    _D3("D3", "无效的文件类型"),
    _D4("D4", "已经处理过的文件"),
    _D5("D5", "无此文件"),
    _D6("D6", "接收者不支持"),
    _D7("D7", "文件锁定"),
    _D8("D8", "未成功"),
    _D9("D9", "文件长度不符"),
    _DA("DA", "文件解压缩错"),
    _DB("DB", "文件名称错"),
    _DC("DC", "无法接收文件"),
    _F1("F1", "文件记录格式错误"),
    _F2("F2", "文件记录重复"),
    _F3("F3", "文件记录不存在"),
    _F4("F4", "文件记录错误"),
    _F5("F5", "文件批量转联机未完成"),
    _N1("N1", "未登折帐目已超限，交易不成功"),
    _P1("P1", "当前卡未在发卡机构留存手机号等通讯联系号码"),
    _Y1("Y1", "成功"),
    _Y3("Y3", "成功"),
    _Z1("Z1", "失败"),
    _Z3("Z3", "失败"),
    ;

    private String code;
    private String desc;

    F39_RspCodeEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public String getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    @Override
    public String toString() {
        return code + "-" + desc;
    }


    public static F39_RspCodeEnum find(String code) {
        F39_RspCodeEnum result = Arrays.stream(F39_RspCodeEnum.values())
                .filter(e -> e.getCode().equals(code)).findFirst().orElse(null);

        if (result == null) {
            throw new BizException(OltpRpcdEnum.PARAM_IS_EMPTY_OR_NULL.getRespCode(), "找不到对应的枚举信息" + code);
        }
        return result;
    }


    public static F39_RspCodeEnum getResult(String f39_RspCode) {
        F39_RspCodeEnum result = Arrays.stream(F39_RspCodeEnum.values())
                .filter(e -> e.getCode().equals(f39_RspCode)).findFirst().orElse(null);

        if (result == null) {
            throw new BizException(OltpRpcdEnum.PARAM_IS_EMPTY_OR_NULL.getRespCode(), "找不到对应的枚举信息" + f39_RspCode);
        }
        return result;
    }


    public static String getRspMsg(String f39_RspCode) {
        return getResult(f39_RspCode).toString();
    }
}
